package cn.utils;
import lombok.extern.slf4j.Slf4j;

import javax.swing.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Objects;
/**
 * @author zchcpy
 * @version 202303251524
 * @projectName xb-qr-device-left
 * @packageName com.singbon.qrcode.utils
 * @className MessageBoxUtil
 * @description MessageBoxUtil
 * @createDate 2023-03-25 15:24
 * @updateDate 2023-03-25 15:24
 */
public class MessageBoxUtil {
  public static void showMsgBox(String message) {
    JOptionPane.showMessageDialog(null, message);
  }
  /**
   * // 0
   * String operation1 = "现在打开";
   * // 1
   * String operation2 = "稍后打开";
   */
  public static Integer showConfirmMsgBox(String message, String title, Object[] possibilities) {
    String successPath = Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("")).getPath() + "img/success.png";
    String failPath = Objects.requireNonNull(Thread.currentThread().getContextClassLoader().getResource("")).getPath() + "img/fail.png";
    successPath = "file:///" + successPath.substring(1);
    failPath = "file:///" + failPath.substring(1);
    URL success = null;
    URL fail = null;
    try {
      success = new URL(successPath);
      fail = new URL(failPath);
    }
    catch (MalformedURLException e) {
      e.printStackTrace();
    }
    Icon icon = null;
    if (success != null && fail != null) {
      icon = new ImageIcon(success);
    }
    int defaultSelectIndex;
    Object defaultSelectObj = "否";
    if (null != possibilities && possibilities.length >= 1) {
      defaultSelectIndex = possibilities.length - 1;
      defaultSelectObj = possibilities[defaultSelectIndex];
    }
    return JOptionPane.showOptionDialog(null, message, title,
      //
      JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, icon, possibilities, defaultSelectObj);
  }
  private MessageBoxUtil() {}
}
